<%--
  Created by IntelliJ IDEA.
  User: gem-inno
  Date: 2018/9/21
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>jsonData演示</title>
    </head>
    <body>
        <script type="text/javascript">
            //定义json数据
            var data = {
                "name" : "edwarder",    //字符串
                "age"  : 20,    //数字
                "isStudent" : true, //boolean值
                "score" : {
                    "chinese" : 88,
                    "math" : 90,
                    "english" : 95
                }, //json对象
                "remarks" : [
                    {"k1" : "v1"},
                    {"k2" : "v2"}
                ]   //数组
            }

            //对json对象的访问
            document.write("name:" + data.name + "<br/>");
            document.write("age:" + data["age"] + "<br/>");
            document.write("chinese:" + data.score.chinese + "<br/>");
            document.write("k1:" + data.remarks[0].k1 + "<br/>");

            //将json对象转成json字符串
            var dataString = JSON.stringify(data);
            document.write("dataString:" + dataString + "<br/>");
            document.write("dataString的类型:" + typeof dataString + "<br/>");

            //json字符串转json对象
            var dataJson = JSON.parse(dataString);
            document.write("isStudent:" + dataJson.isStudent + "<br/>");
        </script>
    </body>
</html>
